import type { ProductStateModel } from './models';

import { requestClient } from '#/api/request';

/**
 * 获取产品数据集合
 * @param params 查询参数
 * @returns 返回查询结果
 */
export async function getProductListApi(params?: any) {
  return requestClient.get<ProductStateModel[]>(
    '/mes/production/productState/list',
    {
      params,
    },
  );
}

/**
 * 分页查询产品数据集合
 * @param params 分页查询参数
 * @returns 返回查询结果
 */
export async function getProductPagedListApi(params?: PageParams) {
  return requestClient.get<PaginationResult<ProductStateModel>>(
    '/mes/production/productState/list-page',
    {
      params,
    },
  );
}

/**
 * 产品让步接收
 * @param id 产品状态 Id
 * @param isCompleted 是否完工
 * @returns 返回结果
 */
export async function concedeProductApi(id: number, isCompleted: boolean) {
  return requestClient.put<boolean>(`/mes/production/productState/concede`, {
    id,
    isCompleted,
  });
}

/**
 * 产品强制不合格
 * @param id 产品状态 Id
 * @returns 返回结果
 */
export async function unfitProductApi(id: number) {
  return requestClient.put<boolean>(`/mes/production/productState/unfit`, {
    id,
  });
}

/**
 * 产品报废
 * @param id 产品状态 Id
 * @param scrapCategory 报废分类
 * @param scrapCategoryName 报废分类名称
 * @param scrapReason 报废原因
 * @returns 返回结果
 */
export async function scrapProductApi(
  id: number,
  scrapCategory: string,
  scrapCategoryName: string,
  scrapReason: string,
) {
  return requestClient.put<boolean>(`/mes/production/productState/scrap`, {
    id,
    scrapCategory,
    scrapCategoryName,
    scrapReason,
  });
}
